package mvc;

public class TicTacToeViewConsole implements TicTacToeListener {

	public TicTacToeViewConsole(TicTacToeModel model) {
		this.model = model;
	}

	TicTacToeModel model;
	
	@Override
	public void pieceWasSet(TicTacToeEvent event) {
		 System.out.println("Player "+event.getPlayer()+" has set "+
		            "a piece on "+event.getRow()+"/" + event.getCol());
		 
		 for (int row = 0; row < 3; row++) {
			 for (int col = 0; col < 3; col++) {
				int piece = model.getPiece(row, col);
				if(piece==TicTacToeModel.PLAYER_NONE)
					System.out.print(".");
				if(piece==TicTacToeModel.PLAYER_O)
					System.out.print("O");
				if(piece==TicTacToeModel.PLAYER_X)
					System.out.print("X");
			}
			 System.out.println();
			
		}
		 System.out.println();
		        
	}

	@Override
	public void statusChanged(TicTacToeEvent event) {
		if(event.isGameOver()){
			System.out.println("Game over");
			int winner = model.getGewinner();
			
			if(winner == model.PLAYER_NONE)
				System.out.println("No winner");
			if(winner == model.PLAYER_X)
				System.out.println("Plazer X winner");
			if(winner == model.PLAYER_O)
				System.out.println("Plazer Y winner");
		}else{
			System.out.println("Game started");
		}
	}

}
